package com.olclass.web.service;

import com.olclass.web.dao.UserRepository;
import com.olclass.web.domain.User;
import com.olclass.web.support.QueryParamUtil;
import com.olclass.web.support.QuerySpecification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * FileName: CollegeService.java
 * Author:   Administrator
 * Date:     2021/3/23 19:12
 * Description:
 */
@Service
@Transactional
public class UserService {
    
    @Autowired
    UserRepository userRepository;

    public Page<User> queryByFilter(String filterParam, String sortParam, int start, int limit) {
        Page<User> results = userRepository.findAll(new QuerySpecification<User>(filterParam),
                new PageRequest(start, limit, QueryParamUtil.parseSortParams(sortParam)));
        return results;
    }


    public User save(User item){
        return  userRepository.save(item);
    }

    public void delete(String id){
        userRepository.delete(id);
    }

    public User findById(String id){
        return  userRepository.findById(id);
    }

    public User checkLogin(String username, String password) throws Exception{

        return userRepository.findByUsernameAndPwd(username,password);

    }
}